<template>
    <div>
        <h1>添加页面</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>科室名称：</td>
                    <td><input type="text" v-model="info.name"></td>
                </tr>
                <tr>
                    <td>人数：</td>
                    <td><input type="text" v-model="info.renShu"></td>
                </tr>
                
                <tr>
                    <td>备注：</td>
                    <td>
                        
                        <textarea v-model="info.text" id="" cols="30" rows="10"></textarea>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button @click="add">添加</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();
let info:any=reactive({
  name : "",
  renShu: "",
  text: "",
 
 
})

const add=()=>{
 if(info.name==""){
   alert('请输入科室名称')
   return; 
 }
 if(info.renShu==""){
   alert('请输入人数')
   return;
 }
 if(info.text==""){
   alert('请输入备注')
   return; 
 }
 axios({
   url:'/api/yisheng/AddKeshi',
   method:'post',
   data :info 
 }) 
.then(res=>{
    if(res.data==-1){
      alert('科室名称不能重复')
      return;
    }
   if(res.data==1){
     alert('添加成功')
     router.push('/KeShiShow')
   }
   else{
     alert('添加失败') 
     return;
   }
 }) 

}
</script>

<style scoped>

</style>